<?php
require_once '../config/config.inc';
$key=$_GET['key'];
$temp_member="temp_user";
$connect=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$connect){
	echo mysql_error();
}
$db=mysql_select_db(DB_DATABASE);
if(!$db){
	die(mysql_error());
}
$sql=mysql_query("SELECT * FROM `temp_user` where `key`='$key'");
if($sql){
	$count=mysql_num_rows($sql);
	if ($count==1){
		$rows=mysql_fetch_array($sql);
		$fullname=$rows['fullname'];
		$email=$rows['email'];
		$password=$rows['password'];
		$photo=$rows['photo'];
		$sql1=mysql_query("insert into `user` VALUES(null,'$fullname', '$email', '$password', '$photo') ");

		if($sql1){
			echo "Your account has been activated";
			$sql2=mysql_query("DELETE FROM `temp_user` WHERE `key`='$key'");
			if(!$sql2){
				echo "VERY BERY BAD: " . mysql_error();
			}
			header("location:../login.php");
		}
		
		else{
			echo "VERY BAD: " . mysql_error();
		}
	}else{
		echo mysql_error();
	}
}
else {
	echo mysql_error();
}
?>